package lock;


import android.app.KeyguardManager;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.widget.Toast;

import com.kkom1.tapeat.R;

import data_management.KeyguardData;

public class TapeatLockService extends Service {
	private LockscreenReceiver r;
	
	public IBinder onBind(Intent intent) {
		throw new UnsupportedOperationException("Not yet implemented");
	}
	
	private void keyguardInit(){
		KeyguardData.km      = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
		KeyguardData.keylock = KeyguardData.km.newKeyguardLock(KEYGUARD_SERVICE);
	}
	
	public void onCreate(){
		keyguardInit();
		KeyguardData.keylock.disableKeyguard();
        
		//set receiver
		IntentFilter ift = new IntentFilter(Intent.ACTION_SCREEN_OFF);
		ift.addAction(Intent.ACTION_BOOT_COMPLETED);

		r = new LockscreenReceiver();
        this.registerReceiver(r, ift);
        
        Toast.makeText(this, R.string.msg_SetLockOn, 0).show();
	}
	
	public int onStartCommand(Intent intent, int flags, int startId){
		return Service.START_STICKY;
	}
	
	public void onDestroy(){
			this.unregisterReceiver(r);
			KeyguardData.keylock.reenableKeyguard();
			Toast.makeText(this, R.string.msg_SetLockOff, 0).show();
	}
}